/*
 * Copyright (c) 2023 iQi.Co.Ltd. All rights reserved.
 */
 
using IQIGame.Onigao.Framework;
using System.Collections.Generic;
using System.Linq;
using System;
using NetProtocol.Enum;

namespace NetProtocol.POD {

	/// <summary>
	///  主城区域信息
	/// module : structs
	/// </summary>
	public class MainCityRegionPOD : IPOD 
    {
        public readonly static Func<MainCityRegionPOD> FACTORY = () => new MainCityRegionPOD();
		public static Func<MainCityRegionPOD> DynamicFactory = FACTORY;
        
		/*-- members --*/
		/// <summary>
        ///  区域cid
        /// </summary>
		public int cid;
		/// <summary>
        ///  天气cid
        /// </summary>
		public int weatherCid;
		/// <summary>
        ///  npc信息
        /// </summary>
        private List<MainCityNpcPOD> m_npcs;
		
		
        public List<MainCityNpcPOD> npcs
        {
            get
            {
                if(m_npcs == null)
                {
                    m_npcs = new();
                }
                return m_npcs;
            }
            private set => m_npcs = value;
        }
        public List<MainCityNpcPOD> unsafe_npcs
        {
        	get => m_npcs;
        	set => m_npcs = value;
        }
		
		/*-- constructors --*/
		public MainCityRegionPOD() {}
		public MainCityRegionPOD(int cid, int weatherCid, List<MainCityNpcPOD> npcs) {
			this.cid = cid;
			this.weatherCid = weatherCid;
			this.m_npcs = npcs;
		}
	      public void Serial(SOutputStream _out) {
            _out.Write_int(cid);
            _out.Write_int(weatherCid);
            _out.Write_list_pod(m_npcs);
        }
        
        public void UnSerial(SInputStream _in) {
            if(!_in.HasRemaining()) return;
            cid = _in.Read_int();
            if(!_in.HasRemaining()) return;
            weatherCid = _in.Read_int();
            if(!_in.HasRemaining()) return;
            m_npcs = _in.Read_list_pod<MainCityNpcPOD>(MainCityNpcPOD.DynamicFactory);
        }
		
		public MainCityRegionPOD Clone() {
            MainCityRegionPOD o = DynamicFactory();
            o.cid = cid;
            o.weatherCid = weatherCid;
            if (m_npcs != null) {
                o.m_npcs = m_npcs.ConvertAll(o => o?.Clone());
            }
            return o;
        }
        
        public void Clear() {
            cid = default;
            weatherCid = default;
            m_npcs = default;
        }
		
        public override string ToString() {
			string str = "";
			str += "MainCityRegionPOD [";
			str += "cid=";
			str += cid;
			str += ", weatherCid=";
			str += weatherCid;
			str += ", npcs=";
			str += m_npcs.ToString<MainCityNpcPOD>();
			str += "]";
			return str;
		}
		
	}
}